import java.io.*;

public class InputStreamTest {
    public static void main(String[] args) {
        try (FileWriter url=new FileWriter("./aaa/bbb/ccc/hello.txt",true)){
            url.write("word");
            url.close();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static void main6(String[] args) {
        try(Writer writer=new FileWriter("./aaa/bbb/ccc/hello.txt")) {
            String arr="hello";
            writer.write(arr);
            writer.close();

        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static void main5(String[] args) {
        try(Writer writer=new FileWriter("./aaa/bbb/ccc/hello.txt")) {
            writer.write("xyz");
          writer.close();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static void main4(String[] args) {
        try(Reader reader=new FileReader("./aaa/bbb/ccc/hello.txt")) {
            while(true){
                char [] arr=new char[1024];
                int len=reader.read(arr);
                if(len==-1){
                    break;
                }
                String str=new String(arr,0,len);
                System.out.println(str);
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static void main3(String[] args) {
        File file=new File("./aaa/bbb/ccc/hello.txt");
        try(FileInputStream inputStream=new FileInputStream(file)) {
            while(true) {
                byte[] arr = new byte[1024];
                int len=inputStream.read(arr,2,5);
                if(len==-1){
                    break;
                }
                for (int i = 0; i <len; i++) {
                    System.out.print(arr[i]+" ");
                }
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static void main2(String[] args) {
        File file=new File("./aaa/bbb/ccc/hello.txt");
        try (FileInputStream inputStream=new FileInputStream(file)){
            while(true) {
                //一次读取多个字符
                byte[] arr = new byte[1024];
                int len = inputStream.read(arr);
                if(len==-1){//这里的len是你实际读取到的字节长度
                    break;
                }
                for (int i = 0; i <len ; i++) {
                    System.out.print(arr[i]+" ");
                }
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static void main1(String[] args) throws FileNotFoundException {
        File file=new File("./aaa/bbb/ccc/hello.txt");
        try(FileInputStream inputStream=new FileInputStream(file)) {
            while(true){
                int len=inputStream.read();
                if(len==-1){//如果读取时负一，说明就是读取到文件末尾
                    break;
                }
                System.out.print(len+" ");
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
